<template>
  <div id="echarts1"></div>
</template>

<script>
import * as echarts from 'echarts';

export default {
  props: ['data'],
  data() {
    return {}
  },
  mounted() {
    this.initEcharts()
  },
  methods: {
    initEcharts(data, labels) {
      const chartDom = document.getElementById('echarts1')
      const myChart = echarts.init(chartDom)
      let option

      option = {
        grid:{
          left:"5%",
          bottom: "9%",
          right:"5%"
        },
        xAxis: {
          type: 'category',
          data:labels
        },
        tooltip: {
          trigger: 'item',
          // formatter: function(params){
          //   console.log(params)
          // }
        },
        color: "#108af1",
        yAxis: {
          type: 'value',
          name: "单位（天）",
          nameTextStyle: {
            color: "#aaa",
            nameLocation: "start",
          },
        },
        series: [
          {
            data: data,
            type: 'bar'
          }
        ]
      };

      option && myChart.setOption(option);
    }
  },
  watch: {
    data({data, labels}) {
      this.initEcharts(data, labels)
    }
  }
}
</script>

<style scoped>
#echarts1 {
  width: 100%;
  height: 500px;
}
</style>
